<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<html>
	<head>
		<title>商家管理</title>
		<script>
    var datatable_content;
	$(function(){
		initTable();
	});
	function initTable(){
		datatable_content = $("#contentTable").dataTable({
		   "bServerSide":true,
           "sAjaxSource":'${ctx}/v2/customers/page',
           "fnServerData": callback,
           "bFilter": false,
           "bSort": false,
           "bAutoWidth":false,
           "sZeroRecords": "查询无记录！",
           "bProcessing": true,
           "oLanguage": {
               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
            },
             "aoColumns":[
             	 {"mData": "customerName"},
             	 {"mData": "customerCode"},
             	 {"mData": "customerIntro"},
             	 {"mData": null},
             	 {"mData": null},
             ],
             "aoColumnDefs":[
             	 {"aTargets": [3],
	               "mRender": function (data, display, row) {
		        	return  "<a data-target='#consignorDetail' onclick='consignorDetailAjax("+row.id+")'  class='btn btn-small btn-default' data-toggle='modal'>管理发货人</a>"+
						    "<a href='${ctx }/v2/customerAreaGroup/view/"+row.id+"' class='btn btn-small btn-default' >网点信息</a>"+
						    "<a href='#' onclick='ajaxSynCustomerAreaGroup(\""+row.customerCode+"\")' data-toggle='modal' class='btn btn-small btn-default'>同步网点</a>"+
							"<a href='#ordenoSourceDeils' onclick='ajaxOrdenoSourceDeils("+row.id+")' data-toggle='modal' class='btn btn-small btn-default'>相关接口</a>"+
							"<a href='${ctx }/v2/customersOrdenoSource/viewsOrderSource/"+row.customerCode+"' class='btn btn-small btn-default' >合单信息设置</a>"+
							"<a href='${ctx }/v2/customerAreaGroup/createBindWarehouse/"+row.customerCode+"' class='btn btn-small btn-default' >绑定仓库设置</a>";
	            	}
	            },
             	 {"aTargets": [4],
	               "mRender": function (data, display, row) {
		        	return  "<a href=\"${ctx}/v2/customers/update/"+row.id+"\" class=\"btn btn-small btn-primary\">更新</a>"+
							"<a class=\"btn btn-danger\" href=\"${ctx}/v2/customers/delete/"+row.id+"\" >删除</a>"+
							"<a class='btn btn-small btn-primary' href='${ctx}/v2/customers/distributeWarehouse/"+row.id+"?state=" + row.distributeWarehouseState + "'>分仓设置</a>";;
	            	}
	            },
             ],
		});
	}
	function callback( sSource, aoData, fnCallback ) {
	 aoData.push( { "name": "search_LIKE_customerName", "value": $("#search_LIKE_customerName").val()});  
		 //查询参数
	   $.ajax({ 
	       "type": "post",
	       "contentType": "application/json", 
	       "url": sSource,    
	       "dataType": "json",   
	       "data": JSON.stringify(aoData),
	       "success": fnCallback  
	   });    
	}
	
	function query(){
		datatable_content.fnDestroy();
		initTable();
	}		
	function ajaxOrdenoSourceDeils(item) {
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/customers/ajaxCustomerInf',
			data : 'id=' + item,
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
					var interfaceString = "";
					if (data.status == "1") {
						interfaceString += "<tr><td>获取商品接口</td><td>"+ data.content.skuSourceInf + "</td></tr>";
						interfaceString += "<tr><td>订单同步接口</td><td>"+ data.content.ordenoSynchroInf + "</td></tr>";
						interfaceString += "<tr><td>出库批次接口</td><td>"+ data.content.tmsBatchAddress + "</td></tr>";
						interfaceString += "<tr><td>中转发出库批次接口</td><td>"+ data.content.forwardBatchAddress + "</td></tr>";
						interfaceString += "<tr><td>订单报表接口</td><td>"+ data.content.ordenoChartInf + "</td></tr>";
						//interfaceString += "<tr><td clospan='2' rowspan='2'>"+ data.content.present + "</td></tr>";
					}
					$("#interface").html(interfaceString);
				} else {
					alert(data.content);
				}

			},
			error : function() {
				alert("获取信息错误");
			}
		});
	}
	
	function ajaxSynCustomerAreaGroup(item) {
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/customerAreaGroup/ajaxSynCustomerAreaGroup',
			data : 'customerCode=' + item,
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
					alert(data.content);
				} else {
					alert(data.content);
				}

			},
			error : function() {
				alert("获取信息错误");
			}
		});
	}
	
	function consignorDetailAjax(id){
				var tempString = "";
				$.ajax({
					type : 'post',
					url : '${ctx}/v2/consignor/consignorDetail',
					data : 'id=' + id,
					dataType : 'json',
					success : function(data) {
						if(data.status == -1) {
							$("#consignorTitle").html(data.content);
							$("#modifyConConfirm").html("新增");			
							$("#consignorDetailBodyOut").html("");
							$("#modifyConConfirm").attr("href","${ctx}/v2/consignor/createConsignor/" + id);
						}
						else if (data.status == 1) {
							var consignor = data.content;
							$("#consignorTitle").html(consignor.customers.customerName + "的发货人详情");
							$("#modifyConConfirm").html("修改");
							$("#consignorDetailBodyOut").html("<table id=\"consignorDetailBody\" class=\"table table-striped table-bordered table-condensed\"></table>");		
							tempString += "<tr><th class=\"span3\">发货人名</th><td class=\"span9\">" + consignor.name + "</td></tr>";		
							tempString += "<tr><th>手机号码</t><td>"+consignor.mobile+"</td></tr>";
							tempString += "<tr><th>电话号码</t><td>"+consignor.phone+"</td></tr>";
							tempString += "<tr><th>邮政编码</t><td>"+consignor.zipcode+"</td></tr>";
							tempString += "<tr><th>国家</t><td>"+consignor.sendCountry+"</td></tr>";
							tempString += "<tr><th>省份</t><td>"+consignor.province+"</td></tr>";
							tempString += "<tr><th>城市</t><td>"+consignor.city+"</td></tr>";
							tempString += "<tr><th>地区</t><td>"+consignor.district+"</td></tr>";
							tempString += "<tr><th>地址</t><td>"+consignor.address+"</td></tr>";
							tempString += "<tr><th>备注</t><td>"+consignor.ugc+"</td></tr>";
							if(consignor.isDefault == "1"){
								tempString += "<tr><th>是否默认发货人</t><td>是</td></tr>";
							}
							if(consignor.isDefault == "0"){
								tempString += "<tr><th>是否默认发货人</t><td>否</td></tr>";
							}
							tempString += "<tr><th>仓库名</t><td>"+consignor.depositoryName+"</td></tr>";
							tempString += "<tr><th>退货提醒</t><td>"+consignor.salesRerurnMessage+"</td></tr>";
							tempString += "<tr><th>退货地址</t><td>"+consignor.salesRerurnAddress+"</td></tr>";
							$("#consignorDetailBody").append(tempString);
							$("#modifyConConfirm").attr("href","${ctx}/v2/consignor/modifyConsignor/" + consignor.id);
						}
					},
					error : function() {
						alert("没有找到该商家对应的发件人信息");
					}
				});
			}
	
</script>
	</head>
	<body>
		<section class="content">
		<div class="row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
			<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
				<form class="form-search" action="#">
					<div class="input-append">
					<span class="add-on">商家名：</span>
					
					<input type="text" name="search_LIKE_customerName" id="search_LIKE_customerName"
						class="input-medium" value="${param.search_LIKE_customerName}" onkeydown='if(event.keyCode==13) {query(); return false;}'>
					<button type="button" class="btn btn-info" onclick="query()">
						搜索
					</button>
					<a class="btn btn-info " href="${ctx}/v2/customers/create">新增商家</a>
					</div>
				</form>
			</div>
			</div>
			</div>
		</div>
		
		<c:if test="${not empty message}">
			<div id="message" class="alert alert-success alert-dismissable">
				<i class="fa fa-check"></i>
				<button class="close" aria-hidden="true" data-dismiss="alert" type="button">×</button>
				${message}
			</div>
		</c:if>
		<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
		<table id="contentTable"
			class="table table-striped table-bordered table-condensed">
			<thead>
				<tr>
					<th>
						商家名
					</th>
					<th>
						商家编码
					</th>
					
					<th>
						商家简介
					</th>
					<th>
						管理
					</th>
					<th>
						操作
					</th>
				</tr>
			</thead>
			<tbody>
			</tbody>
		</table>
		</div>
		</div>
		</div>
		</div>
<div id="expressMessage">

</div>
		<div id="ordenoSourceDeils" class="modal fade" tabindex="-1"
			role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
			>
			<div class="modal-dialog" style="width: 60%;">
			<div class="modal-content">
			<div class="modal-header">
				<h3>
					接口地址信息
				</h3>
			</div>
			<div class="modal-body">
			<div class="box box-solid box-primary">
				<table class="table table-striped table-bordered table-condensed">
					<thead>
						<tr>
							<th>
								接口描述
							</th>
							<th>
								接口地址
							</th>
						</tr>
					</thead>
					<tbody id="interface">
					</tbody>
				</table>
			</div>
			<div class="modal-footer bg-gray">
				<button class="btn" data-dismiss="modal" aria-hidden="true">
					关闭
				</button>
			</div>
			</div>
			</div>
			</div>
		</div>
		
		<div id="consignorDetail"  class="modal fade">
		<div class="modal-dialog" style="width: 60%;">
		<div class="modal-content">
			<div class="modal-header">
				<h4 id="consignorTitle">发货人详情</h4>
			</div>
			<div id="consignorDetailBodyOut" class="modal-body">
				<table id="consignorDetailBody" class="table table-striped table-bordered table-condensed"></table>
			</div>
			<div class="modal-footer bg-gray">
				<a id="modifyConConfirm" class="btn btn-primary"></a>
				<button class="btn" data-dismiss="modal" aria-hidden="true">返回</button>
			</div>
		</div>	
		</div>	
		</div>
		</section>
	</body>
</html>
